package org.spiderflow.core.expression.parsing.ast;

import org.spiderflow.core.expression.ExpressionTemplate;
import org.spiderflow.core.expression.ExpressionTemplateContext;
import org.spiderflow.core.expression.parsing.Span;

import javax.xml.transform.Source;
import java.io.IOException;

/**
 * Base class for all AST nodes. A node minimally stores the {@link Span} that references its location in the
 * {@link Source}.
 *
 * @author zhaoshihao
 * @version 2021/11/9 14:35
 **/
public abstract class Node {
    private final Span span;

    protected Node(Span span) {
        this.span = span;
    }

    /**
     * Returns the {@link Span} referencing this node's location in the {@link Source}.
     **/
    public Span getSpan() {
        return span;
    }

    @Override
    public String toString() {
        return span.getText();
    }

    public abstract Object evaluate(ExpressionTemplate template, ExpressionTemplateContext context) throws IOException;
}
